package cn.itcast.tramsformation;

import org.apache.flink.api.common.RuntimeExecutionMode;
import org.apache.flink.api.common.functions.FlatMapFunction;
import org.apache.flink.api.java.tuple.Tuple2;
import org.apache.flink.streaming.api.datastream.DataStreamSource;
import org.apache.flink.streaming.api.environment.StreamExecutionEnvironment;
import org.apache.flink.util.Collector;

/**
 * @author KTL
 * @version V1.0
 * @Package cn.itcast.tramsformation
 * @date 2021/2/24 0024 10:51
 * @Copyright © 2015-04-29  One for each, and two for each
 *              演示Transformations-各种分区
 *
 */
public class TransformationsDemo03 {

    public static void main(String[] args) {
        final StreamExecutionEnvironment env = StreamExecutionEnvironment.getExecutionEnvironment();
        env.setRuntimeMode(RuntimeExecutionMode.AUTOMATIC);


        final DataStreamSource<String> lineDS = env.readTextFile("input/words.txt");

        lineDS.flatMap(new FlatMapFunction<String, Tuple2<String,Integer>>() {
            @Override
            public void flatMap(String value, Collector<Tuple2<String, Integer>> out) throws Exception {
                final String[] s = value.split(" ");
                for (String s1 : s) {
                    out.collect(Tuple2.of(s1,1));
                }
            }
        });
    }


}
